# -*- coding: utf-8 -*-

#importacao of the modulos
#Joao Alturas_6197
#2013_11_25

import csv
import sys
import numpy as np
import matplotlib.pyplot as plt

from sqlalchemy import create_engine

from sqlalchemy.orm import sessionmaker

from sqlalchemy import Column, Integer, String, func

from sqlalchemy.ext.declarative import declarative_base


engine = create_engine('sqlite:///treta.db')

Base = declarative_base()

class Dados(Base):
	__tablename__ = 'dados'	
	id = Column(Integer, primary_key=True)					
	codIntituicao = Column(String(50))
	codCurso = Column(String(20)) 	 
	nomeInstituicao = Column(String(100))     
	nomeCurso = Column(String(100))   
	grau = Column(String(50)) 
	vagasIniciais = Column(String(20)) 
	colocados = Column (String(20))  
	notaUltCand = Column (String(20))  
	vagasSobrantes = Column (String(20)) 
	
    
	def __init__(self, 
		codIntituicao,
		codCurso,
		nomeInstituicao,
		nomeCurso,
		grau,
		vagasIniciais,
		colocados,
		notaUltCand,
		vagasSobrantes):								 
			self.codIntituicao = codIntituicao
			self.codCurso = codCurso	 
			self.nomeInstituicao = nomeInstituicao
			self.nomeCurso = nomeCurso
			self.grau = grau
			self.vagasIniciais = vagasIniciais
			self.colocados = colocados
			self.notaUltCand = notaUltCand
			self.vagasSobrantes = vagasSobrantes
            
Base.metadata.create_all(engine)


Session = sessionmaker(bind=engine)
session = Session()

#Inserir dados
"""
spamReader = csv.reader(open("csvFile.csv", "r"), delimiter=',')
x = 0
for row in spamReader: # Read row of csvFile
	for i in range(0,8):
		row[i] = row[i].replace(",", r'.');
		row[i] = row[i].replace("\\", r'\\\\');
		row[i] = row[i].decode("utf-8")
		pass
	try:
		dado = Dados(row[0], row[1],row[2], row[3], row[4], row[5], row[6], row[7], row[8])
		session.add(dado)
		session.commit()
	except Exception, err:
		print err
		print row
		x = 1
"""
